import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

// PersonSortable2 类
class PersonSortable2 {
    private String name;
    private int age;

    // 有参构造函数
    public PersonSortable2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // toString 方法
    @Override
    public String toString() {
        return name + "-" + age;
    }

    // Getter 方法
    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}

// NameComparator 类，按 name 升序排序
class NameComparator implements Comparator<PersonSortable2> {
    @Override
    public int compare(PersonSortable2 p1, PersonSortable2 p2) {
        return p1.getName().compareTo(p2.getName());
    }
}

// AgeComparator 类，按 age 升序排序
class AgeComparator implements Comparator<PersonSortable2> {
    @Override
    public int compare(PersonSortable2 p1, PersonSortable2 p2) {
        return Integer.compare(p1.getAge(), p2.getAge());
    }
}

// 主类
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // 输入 n
        scanner.nextLine(); // 消耗换行符

        // 创建 PersonSortable2 数组
        PersonSortable2[] people = new PersonSortable2[n];
        for (int i = 0; i < n; i++) {
            String[] input = scanner.nextLine().split(" ");
            String name = input[0];
            int age = Integer.parseInt(input[1]);
            people[i] = new PersonSortable2(name, age);
        }

        // 按 name 升序排序并输出
        Arrays.sort(people, new NameComparator());
        System.out.println("NameComparator:sort");
        for (PersonSortable2 person : people) {
            System.out.println(person);
        }

        // 按 age 升序排序并输出
        Arrays.sort(people, new AgeComparator());
        System.out.println("AgeComparator:sort");
        for (PersonSortable2 person : people) {
            System.out.println(person);
        }

        // 输出 NameComparator 和 AgeComparator 实现的接口
        System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
        System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));

        scanner.close();
    }
}